import threading
import time
import queue


# 模拟的 AIModel 类
class AIModel:
    def __init__(self):
        pass

    def reply(self, message):
        # 这里简单地返回一个模拟的 AI 回复
        return f'[AI回复]: 你说的是 "{message}" 吗？'


# 模拟的微信接口类
class WeChatInterface:
    def __init__(self):
        self.message_queue = queue.Queue()  # 消息队列

    def start_message_listener(self):
        def message_listener():
            while True:
                # 模拟从微信接收消息
                received_message = input('输入收到的消息（输入 exit 退出）：')
                if received_message.lower() == 'exit':
                    break
                self.message_queue.put(received_message)

        # 启动消息监听线程
        threading.Thread(target=message_listener, daemon=True).start()

    def get_new_message(self):
        # 从队列中获取新消息
        if not self.message_queue.empty():
            return self.message_queue.get()
        return None

    def send_message(self, message):
        # 模拟发送消息
        print(f'发送消息：{message}')


# 自动回复机器人类
class AutoReplyBot:
    def __init__(self, wechat_interface, ai_model):
        self.wechat = wechat_interface
        self.ai = ai_model

    def run(self):
        self.wechat.start_message_listener()  # 启动消息监听线程

        while True:
            time.sleep(1)  # 每秒检查一次消息
            new_message = self.wechat.get_new_message()

            if new_message:
                ai_reply = self.ai.reply(new_message)
                self.wechat.send_message(ai_reply)


if __name__ == '__main__':
    pass
